//
//  tklImgView.m
//  wanyibeta
//
//  Created by wxt on 2018/12/6.
//  Copyright © 2018年 wxt. All rights reserved.
//

#import "tklImgView.h"

@implementation tklImgView
+(instancetype)imgViewWithFrame:(CGRect)frame
                            img:(NSString *)img{
    
    
    tklImgView * imgView = [[tklImgView alloc]initWithFrame:frame];
//    imgView.contentMode = UIViewContentModeScaleAspectFit
    imgView.image = [UIImage imageNamed:img];
    
    return imgView;
    
}
+(instancetype)imgViewWithFrame1:(CGRect)frame
                            img:(NSString *)img{
    
    
    tklImgView * imgView = [[tklImgView alloc]initWithFrame:frame];
    
//    imgView.contentMode = UIViewContentModeScaleAspectFit
    imgView.image = [UIImage imageNamed:img];
    imgView.layer.cornerRadius = frame.size.width/2;
    imgView.layer.masksToBounds = YES;
    return imgView;
    
}
+ (UIImage *)kj_clipImage:(UIImage *)image Size:(CGSize)size IsScaleToMax:(BOOL)isScaleToMax {
    CGFloat scale = [UIScreen mainScreen].scale;
    UIGraphicsBeginImageContextWithOptions(size, NO, scale);
    CGSize aspectFitSize = CGSizeZero;
    if (image.size.width != 0 && image.size.height != 0) {
        CGFloat rateWidth = size.width / image.size.width;
        CGFloat rateHeight = size.height / image.size.height;
        
        CGFloat rate = isScaleToMax ? MAX(rateHeight, rateWidth) : MIN(rateHeight, rateWidth);
        aspectFitSize = CGSizeMake(image.size.width * rate, image.size.height * rate);
    }
    
    [image drawInRect:CGRectMake(0, 0, aspectFitSize.width, aspectFitSize.height)];
    UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return finalImage;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
